<template>
	<view>
		<view class="head">
			<view class="head_left" @tap="back()">
				<image src="../../../static/wode/return.png" mode=""></image>
				<text>返回</text>
			</view>
			<view class="head_mid">
				编辑昵称
			</view>
			<view class="head_right" @tap="changeName">
				确定
			</view>
		</view>
		<input class="body_item" pplaceholder="请输入昵称" v-model="nick_name">

		</input>
	</view>
</template>

<script>
	import webim from "../../../common/webim_wx.min.js"
	export default {
		data() {
			return {
				nick_name: uni.getStorageSync('nick_name'),
			};
		},
		methods: {
			back() { //返回
				uni.navigateBack({
					delta: 1
				})
			},
			changeName() {
				var me=this;
				var data = {
					nick_name: this.nick_name,
					user_id: uni.getStorageSync('user_id')
				}
				this.myAjaxNewPost({
					model: 'user',
					controllerName: 'userInfo',
					actionName: 'update',
					data: data,
					successBack: function(res) {
						console.log(res)
						if (res.data.code == 0) {
							uni.showToast({
								title: '修改成功',
								icon: null
							});
							uni.setStorageSync('nick_name', me.nick_name);
							console.log(me.nick_name)
							me.setProfilePortrait()
							uni.navigateBack({
								delta: 1
							})
						}
					}
				})
			},
			setProfilePortrait(){//设置腾讯云名字
				var profile_item = [{
						"Tag": "Tag_Profile_IM_Nick",
						"Value": this.nick_name
					}
				];
				var options = {
					'ProfileItem': profile_item
				};
				
				webim.setProfilePortrait(
					options,
					function(resp) {
						
					},
					function(err) {
						console.log(err.ErrorInfo);
					}
				);
			},
		},
	}
</script>

<style scoped>
	.head {
		display: flex;
		justify-content: space-between;
		height: 128upx;
		background: #ffffff;
		padding: 0 24upx;
	}

	.head image {
		width: 20upx;
		height: 36upx;
		margin-right: 9upx;
	}

	.head_left {
		display: flex;
		align-items: center;
		color: #666666;
		font-size: 32upx;
	}

	.head_mid {
		color: #333333;
		font-size: 36upx;
	}

	.head_right {
		color: #333333;
		font-size: 32upx;
	}

	.body_item {
		background: #ffffff;
		margin-top: 80upx;
		padding: 24upx 24upx;
	}
</style>
